package cn.wolfcode.business.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.wolfcode.business.vo.HistoryVO;
import cn.wolfcode.business.vo.PackageAuditVO;
import org.apache.poi.util.IOUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.enums.BusinessType;
import cn.wolfcode.business.domain.CarPackageAudit;
import cn.wolfcode.business.service.ICarPackageAuditService;
import cn.wolfcode.common.utils.poi.ExcelUtil;
import cn.wolfcode.common.core.page.TableDataInfo;

/**
 * 套餐信息Controller
 * 
 * @author dafei
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/business/carPackageAudit")
public class CarPackageAuditController extends BaseController
{
    @Autowired
    private ICarPackageAuditService carPackageAuditService;

    /**
     * 查询套餐信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarPackageAudit carPackageAudit)
    {
        startPage();
        List<CarPackageAudit> list = carPackageAuditService.selectCarPackageAuditList(carPackageAudit);
        return getDataTable(list);
    }

    /**
     * 查询套餐信息列表-todo
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:todo')")
    @GetMapping("/todo")
    public TableDataInfo todo(CarPackageAudit carPackageAudit)
    {

        //startPage();
        List<CarPackageAudit> list = carPackageAuditService.todoQuery(carPackageAudit);
        if(list == null || list.size() == 0){
            return new  TableDataInfo(Collections.emptyList(), 0);
        }
        return getDataTable(list);
    }
    /**
     * 查询套餐信息列表-done
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:done')")
    @GetMapping("/done")
    public TableDataInfo done(CarPackageAudit carPackageAudit)
    {

        //startPage();
        List<CarPackageAudit> list = carPackageAuditService.doneQuery(carPackageAudit);
        if(list == null || list.size() == 0){
            return new  TableDataInfo(Collections.emptyList(), 0);
        }
        return getDataTable(list);
    }

    /**
     * 导出套餐信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:export')")
    @Log(title = "套餐信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarPackageAudit carPackageAudit)
    {
        List<CarPackageAudit> list = carPackageAuditService.selectCarPackageAuditList(carPackageAudit);
        ExcelUtil<CarPackageAudit> util = new ExcelUtil<CarPackageAudit>(CarPackageAudit.class);
        util.exportExcel(response, list, "套餐信息数据");
    }

    /**
     * 获取套餐信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(carPackageAuditService.selectCarPackageAuditById(id));
    }

    /**
     * 新增套餐信息
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:add')")
    @Log(title = "套餐信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarPackageAudit carPackageAudit)
    {
        return toAjax(carPackageAuditService.insertCarPackageAudit(carPackageAudit));
    }

    /**
     * 修改套餐信息
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:edit')")
    @Log(title = "套餐信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarPackageAudit carPackageAudit)
    {
        return toAjax(carPackageAuditService.updateCarPackageAudit(carPackageAudit));
    }

    /**
     * 删除套餐信息
     */
    @PreAuthorize("@ss.hasPermi('business:carPackageAudit:remove')")
    @Log(title = "套餐信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carPackageAuditService.deleteCarPackageAuditByIds(ids));
    }


    /**
     * 流程信息审核-进度查看
     */
    //@PreAuthorize("@ss.hasPermi('business:carPackageAudit:process')")
    @Log(title = "套餐信息", businessType = BusinessType.OTHER)
    @GetMapping("/process/{id}")
    public void processImg( @PathVariable Long id, HttpServletResponse response) throws IOException {
        InputStream inputStream = carPackageAuditService.getProcessImg(id);
        IOUtils.copy(inputStream, response.getOutputStream());
    }


    /**
     * 流程信息审核-撤销
     */
    //@PreAuthorize("@ss.hasPermi('business:carPackageAudit:cancel')")
    @Log(title = "套餐信息", businessType = BusinessType.OTHER)
    @PostMapping("/cancel/{id}")
    public AjaxResult processImg( @PathVariable Long id)  {
        carPackageAuditService.auditCancel(id);
        return AjaxResult.success();
    }


    /**
     * 流程信息审核-查历史
     */
    //@PreAuthorize("@ss.hasPermi('business:carPackageAudit:history')")
    @Log(title = "套餐信息", businessType = BusinessType.OTHER)
    @GetMapping("/history/{instanceId}")
    public AjaxResult history( @PathVariable Long instanceId)  {
        List<HistoryVO> list = carPackageAuditService.queryHistory(instanceId);
        return AjaxResult.success(list);
    }

    /**
     * 流程信息审核-查历史
     */
    //@PreAuthorize("@ss.hasPermi('business:carPackageAudit:audit')")
    @Log(title = "套餐信息", businessType = BusinessType.OTHER)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody PackageAuditVO vo)  {
        carPackageAuditService.audit(vo);
        return AjaxResult.success();
    }

}
